
/**
* @Title: JedisClientSingle.java
* @Package com.leetone.rest.dao.impl
* @Description: 【】
* @date 2018年3月24日 上午9:52:24
* @version V1.0
* @Company: 上海
* @author:[谭磊][leetone123@163.com]
*/

package com.leetone.rest.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.leetone.rest.dao.JedisClient;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
* @ClassName: JedisClientSingle
* @Description: 【Jedis单机版实现类】
* @date 2018年3月24日 上午9:52:24
* @Company: 上海
* @author:[谭磊][leetone123@163.com]
*/
//@Repository【此处不要加该注解，因为有单机版和集群版，可以在配置文件中自由配置】
public class JedisClientSingle implements JedisClient {
	@Autowired
	private JedisPool jedisPool;
	/* (非 Javadoc)
	* 
	* 
	* @param key
	* @return
	* @see com.leetone.rest.dao.JedisClient#get(java.lang.String)
	*/

	@Override
	public String get(String key) {
		Jedis jedis = jedisPool.getResource();
		String res = jedis.get(key);
		jedis.close();
		return res;
	}

	/* (非 Javadoc)
	* 
	* 
	* @param key
	* @param value
	* @return
	* @see com.leetone.rest.dao.JedisClient#set(java.lang.String, java.lang.String)
	*/

	@Override
	public String set(String key, String value) {
		Jedis jedis = jedisPool.getResource();
		String res = jedis.set(key, value);
		jedis.close();
		return res;
	}

	/* (非 Javadoc)
	* 
	* 
	* @param hkey
	* @param key
	* @return
	* @see com.leetone.rest.dao.JedisClient#hget(java.lang.String, java.lang.String)
	*/

	@Override
	public String hget(String hkey, String key) {
		Jedis jedis = jedisPool.getResource();
		String res = jedis.hget(hkey, key);
		jedis.close();
		return res;
	}

	/* (非 Javadoc)
	* 
	* 
	* @param hkey
	* @param key
	* @param value
	* @return
	* @see com.leetone.rest.dao.JedisClient#hset(java.lang.String, java.lang.String, java.lang.String)
	*/

	@Override
	public Long hset(String hkey, String key, String value) {
		Jedis jedis = jedisPool.getResource();
		Long res = jedis.hset(hkey, key, value);
		jedis.close();
		return res;
	}

	/* (非 Javadoc)
	* 
	* 
	* @param key
	* @return
	* @see com.leetone.rest.dao.JedisClient#incr(java.lang.String)
	*/

	@Override
	public long incr(String key) {
		Jedis jedis = jedisPool.getResource();
		Long res = jedis.incr(key);
		jedis.close();
		return res;
	}

	/* (非 Javadoc)
	* 
	* 
	* @param key
	* @param second
	* @return
	* @see com.leetone.rest.dao.JedisClient#expire(java.lang.String, long)
	*/

	@Override
	public long expire(String key, int second) {
		Jedis jedis = jedisPool.getResource();
		Long res = jedis.expire(key, second);
		jedis.close();
		return res;
	}

	/* (非 Javadoc)
	* 
	* 
	* @param key
	* @return
	* @see com.leetone.rest.dao.JedisClient#ttl(java.lang.String)
	*/

	@Override
	public long ttl(String key) {
		Jedis jedis = jedisPool.getResource();
		Long res = jedis.ttl(key);
		jedis.close();
		return res;
	}

	@Override
	public long del(String key) {
		Jedis jedis = jedisPool.getResource();
		Long res = jedis.del(key);
		jedis.close();
		return res;
	}

	@Override
	public long hdel(String hkey, String key) {
		Jedis jedis = jedisPool.getResource();
		Long res = jedis.hdel(hkey, key);
		jedis.close();
		return res;
	}

}
